﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.OleDb;
using System.IO;
using ADOX;

namespace Shine.Util.Data
{
    /// <summary>
    /// 数据库操作类型
    /// </summary>
    public class DatabaseHelper
    {
        /// <summary>
        /// 创建Access数据库文件，若文件已经存在，则删除后重新创建。
        /// </summary>
        /// <param name="fullname">数据库文件的全路径</param>
        /// <returns></returns>
        public static void CreateAccess(string fullname)
        {
            Catalog cat = new Catalog();
            if (File.Exists(fullname) == true) File.Delete(fullname);
            string str = "provider=Microsoft.Jet.OleDb.4.0;Data Source=" + fullname;
            cat.Create(str);
            cat = null;
        }

        /// <summary>
        /// 获取Access数据库的连接对象
        /// </summary>
        /// <param name="fullname">数据库文件的全路径</param>
        /// <returns></returns>
        public static OleDbConnection GetAccessConnection(string fullname)
        {
            string str = "provider=Microsoft.Jet.OleDb.4.0;Data Source=" + fullname;
            return new OleDbConnection(str);
        }
    }
}
